package com.moke.wp.wx_weimai.config.web;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.file.Path;
import java.nio.file.Paths;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 获取 upFile 目录的绝对路径
        Path uploadDir = Paths.get("./upFile").toAbsolutePath().normalize();
        String uploadPath = uploadDir.toString();

        // 将 /images/** 映射到 upFile 目录
        registry.addResourceHandler("/images/**")
                .addResourceLocations("file:" + uploadPath + "/");
    }
}
